package cn.zhentao.controller;

import cn.zhentao.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("login")
    @ResponseBody
    public String login(@RequestBody(required = false) String body){
        System.out.println(body);
        return "success";
    }

    @ModelAttribute
    public void showModel(User user){
        user.setName("tom");
        System.out.println("执行了 showModel方法"+user.getName());
    }

    @RequestMapping("/testModelAttribute")
    @ResponseBody
    public String testModelAttribute(User user){
        System.out.println("执行控制器方法："+user.getName());
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/testJson")
    @ResponseBody
    public User testJson(){
        User user = new User("tom",12);
        return user;
    }

    @RequestMapping("/helloPage")
    public String hello2(){
        return "../hello.html";
    }



    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        System.out.println("hello world");
        //返回值：指定的文件名
        return "success";
    }
}
